package model;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.example.towerdefence.R;

import controller.GameBoard;

import model.enemies.ArmoredEnemy;
import model.enemies.Boss;
import model.enemies.HeavyEnemy;
import model.enemies.IEnemy;
import model.enemies.SpeedEnemy;
import model.surface.Map;
import model.surface.PathPoint;
import model.towers.FireTower;
import model.towers.FrostTower;
import model.towers.ITower;
import model.towers.LaserTower;
import model.utils.Speed;
import android.graphics.Bitmap;
import model.enums.Enemies;
import model.enums.Towers;

/**
 * Factory class for creating enemies and towers.
 * 
 * @author EvilTeam
 * 
 */
public class Factory {

	private static final int ARMOR = 50;
	private static final int HEAVY_ENEMY_HEALTH = 200;
	private static final int ENEMY_HEALTH = 100;
	private static final int SLOW_RATE = 4;
	private static final int LASER_TOWER_DAMAGE = 7;
	private static final int FIRE_TOWER_DAMAGE = 5;
	private static final int FROST_TOWER_SHOOTING_SPEED = 4;
	private static final int TOWER_SHOOTING_SPEED = 3;
	private static final float RANGE = 130;
	private static final int FIRE_TOWER_PRICE = Integer.parseInt(GameBoard
			.getRes().getString(R.string.tower1Cost));
	private static final int LASER_TOWER_PRICE = Integer.parseInt(GameBoard
			.getRes().getString(R.string.tower2Cost));
	private static final int FROST_TOWER_PRICE = Integer.parseInt(GameBoard
			.getRes().getString(R.string.tower3Cost));
	private static List<PathPoint> pathArray = Map.getPath();

	/**
	 * Factory method for creating towers.
	 * 
	 * @param tower
	 * @param xAxisPoint
	 * @param yAxisPoint
	 * @param enemy
	 * @return
	 */
	public static ITower getTower(Towers tower, float xAxisPoint,
			float yAxisPoint, CopyOnWriteArrayList<IEnemy> enemy) {

		switch (tower) {
		case FIRE_TOWER:
			return new FireTower(xAxisPoint, yAxisPoint, FIRE_TOWER_PRICE,
					RANGE, TOWER_SHOOTING_SPEED, FIRE_TOWER_DAMAGE, enemy);
		case FROST_TOWER:
			return new FrostTower(xAxisPoint, yAxisPoint, FROST_TOWER_PRICE,
					RANGE, FROST_TOWER_SHOOTING_SPEED, enemy, SLOW_RATE);
		case LASER_TOWER:
			return new LaserTower(xAxisPoint, yAxisPoint, LASER_TOWER_PRICE,
					RANGE, TOWER_SHOOTING_SPEED, LASER_TOWER_DAMAGE, enemy);
		default:
			return null;
		}
	}

	/**
	 * Factory method for creating enemies.
	 * 
	 * @param enemy
	 * @param xAxisPoint
	 * @param yAxisPoint
	 * @param bitmap
	 * @return
	 */
	public static IEnemy getEnemy(Enemies enemy, float xAxisPoint,
			float yAxisPoint, Bitmap bitmap) {
		switch (enemy) {
		case SPEED_ENEMY:
			return new SpeedEnemy(xAxisPoint, yAxisPoint, new Speed(15, 0),
					ENEMY_HEALTH, bitmap, pathArray);
		case ARMORED_ENEMY:
			return new ArmoredEnemy(xAxisPoint, yAxisPoint, new Speed(11, 0),
					ARMOR, ENEMY_HEALTH, bitmap, pathArray);
		case HEAVY_ENEMY:
			return new HeavyEnemy(xAxisPoint, yAxisPoint, new Speed(7, 0),
					HEAVY_ENEMY_HEALTH, bitmap, pathArray);
		case BOSS:
			return new Boss(xAxisPoint, yAxisPoint, new Speed(13, 0), ARMOR,
					HEAVY_ENEMY_HEALTH, bitmap, pathArray);
		default:
			return null;
		}
	}

}
